package org.csu.mybigpro.persistence;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.csu.mybigpro.DTO.ClassroomBookingDTO;
import org.csu.mybigpro.domain.ClassroomBooking;

import java.util.List;

@Mapper
public interface ClassroomBookingMapper extends BaseMapper<ClassroomBooking> {
    @Select("SELECT cb.* FROM classroom_booking cb " +
            "JOIN user u ON cb.teacher_id = u.id " +
            "WHERE u.name LIKE CONCAT('%', #{teacherName}, '%')")
    List<ClassroomBooking> selectByTeacherName(@Param("teacherName") String teacherName);

    @Select("SELECT cb.* FROM classroom_booking cb " +
            "JOIN classroom c ON cb.classroom_id = c.id " +
            "WHERE c.room_number LIKE CONCAT('%', #{roomNumber}, '%')")
    List<ClassroomBooking> selectByRoomNumber(@Param("roomNumber") String roomNumber);

    @Select("SELECT cb.id, u.name AS teacher_name, c.room_number AS classroom_number, cb.status, cb.apply_time, cb.review_time, cb.remark " +
            "FROM classroom_booking cb " +
            "LEFT JOIN user u ON cb.teacher_id = u.id " +
            "LEFT JOIN classroom c ON cb.classroom_id = c.id ")
    List<ClassroomBookingDTO> selectReviewedWithTeacherAndClassroom();

}
